<?php

namespace app\controller\admin\module;

class BaseController extends \app\BaseController
{

    /**
     * 设置登录信息
     * @param $token
     * @param $data
     * @return void
     */
    protected function setLoginData($token, $data){
        setCaches($token, $data, LOGIN_TIME_OUT);  //重置信息时间
    }


    protected function makeMyAuth($gid): array
    {
        $auth = Model('auth')->getList(['gid' => $gid], 'mid');
        $list = !empty($auth) ? Model('menu')->getList(['id' => array_column($auth, 'mid'), 'status' => 1, 'level' => 3], 'id, name, controller, controller_alias, method, method_alias, request_method') : [];
        $auth = [];
        if(!empty($list)){
            foreach($list as $v){
                switch ($v['request_method']){
                    case 1:
                        $requestMethod = 'GET';
                        break;
                    case 2:
                        $requestMethod = 'POST';
                        break;
                    case 3:
                        $requestMethod = 'PUT';
                        break;
                    case 4:
                        $requestMethod = 'DELETE';
                        break;
                    default:
                        $requestMethod = 'GET';
                }
                $auth[] = $requestMethod . ':/admin/' . ($v['controller_alias'] ? : strtolower($v['controller'])) . (!empty($v['method']) ? '/' . ($v['method_alias'] ? : strtolower($v['method'])) : '');
            }
        }
        return $auth;
    }

}